<layout name="layout" />
<div class="pageheader">
	<h1 class="pagetitle">
		<if condition="$is_run_kawei == true">
			<a href="/" class="linkWay">首页/新增卡位</a>
			&nbsp;<span class="divider">»</span>&nbsp;
			<a href="/shortcut/campaigns" class="linkWay">选择要卡位的推广组</a>
			&nbsp;<span class="divider">»</span>&nbsp;
			<a href="#" class="currentWay">选择需要卡位的关键词</a><else/>
			<a href="#" class="currentWay">快捷功能：关键词批量优化</a>
		</if>
	</h1>
</div>
<div id="contentwrapper" class="contentwrapper nopadding">
	<div id="keyword_manager">
		<div class="loading" style="height:200px;text-align:center">
			正在加载关键词信息，请稍后<img src="/Img/loader1.gif" />
		</div>
	</div>
</div>

<script id="template_keyword_reporter" type="text/html">
	<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable">
		<thead id="km_thead" >
		<tr>
			<th width="40px" class="head0 nolborder" style="padding: 0;">
				<a id="selectall" style="border:0px;text-indent:-9999px;" class="btn btn3 btn_unselectall btn_selectall tooltips" href="javascript:void(0);" title="全选">全选</a>
			</th>
			<th width="75px" class="head1">关键词 ( <span id="keyword_count">0</span> 个)</th>
			<th width="170px" class="head0 center">推广单元名称</th>
			<th width="42px" class="head1 sortable desc" data-sort='impressions'>展现量</th>
			<th width="43px" class="head0 sortable" data-sort='click'>点击量</th>
			<th width="43px" class="head1 sortable" data-sort='ctr'>点击率</th>
			<th width="44px" class="head0 sortable" data-sort='cpc'>平均点击花费</th>
			<th width="44px" class="head1 sortable" data-sort='cvr'>点击转化率</th>
			<th width="44px" class="head0 sortable" data-sort='avgpos'>宝贝排名</th>
			<th width="44px" class="head1 sortable" data-sort='ravgpos'>实时排名</th>
			<th width="44px" class="head0 sortable" data-sort='qscore'>计算机质量得分</th>
			<th width="44px" class="head0 sortable" data-sort='wireless_qscore'>移动质量得分</th>
			<th width="44px" class="head1 sortable" data-sort='cost'>总花费</th>
			<th width="44px" class="head0 sortable" data-sort='sales'>总成交金额</th>
			<th width="44px" class="head0 sortable" data-sort='total_pay_count'>总成交笔数</th>
			<th width="44px" class="head1 sortable" data-sort='roi'>投入产出比</th>
			<th width="44px" class="head0 sortable" data-sort='fav_count'>总收藏数</th>
			<th width="44px" class="head0 sortable" data-sort='fav_count_rate'>收藏率</th>
			<th width="44px" class="head0 sortable" data-sort='cart_total'>购物车数</th>
			<th width="44px" class="head0 sortable" data-sort='cart_total_rate'>购物车率</th>
			<th width="46px" class="head1">出价(计算机)</th>
			<th width="46px" class="head0">出价(移动)</th>
			<th width="77px" class="head1">操作</th>
		</tr>
		</thead>
		<tbody id="keywords_tbody">

		</tbody>
	</table>
</script>
<layout name="layout" />
<div class="pageheader">
	<h1 class="pagetitle">
		<if condition="$is_run_kawei == true">
			<a href="/" class="linkWay">首页/新增卡位</a>
			&nbsp;<span class="divider">»</span>&nbsp;
			<a href="/shortcut/campaigns" class="linkWay">选择要卡位的推广组</a>
			&nbsp;<span class="divider">»</span>&nbsp;
			<a href="#" class="currentWay">选择需要卡位的关键词</a><else/>
			<a href="#" class="currentWay">快捷功能：关键词批量优化</a>
		</if>
	</h1>
</div>
<style>
	.condition-input{
		width: 50px;
		display: inline-block;
	}
	.w-30{width:30%}.overviewtable_plan tr td,.overviewtable_plan tr th{text-align:left!important}.center{text-align:center!important}a.btn:hover{text-decoration:none;color:#333;border:none}.campaign_status{height:26px;line-height:26px}

	.metrotable thead th.sortable, .metrotable thead td.sorting {
		padding-left: 0px;
		padding-right:0px;
		padding-top:10px;;
		padding-bottom: 20px;
	}
	.metrotable td.sortable {
		padding-left: 0px;
	}
	.metrotable td {
		padding:0;
	}
	.metrotable thead th {
		border-bottom: 1px solid #D8D8D8;
		line-height: 20px;
		text-align: center;
		font-size: 12px;
		padding: 0px 0px;
	}
</style>
<div id="contentwrapper" class="contentwrapper nopadding">
	<div  id="keywords_toolbar" class="toolbar-wrapper">
		<div class="btn-toolbar" >
			<if condition="!$is_run_kawei">
				<div class="btn-group-dropdown">
					<a  id="addprice"  class="btn btn3 btn_grey btn_higherprice tooltips" href="javascript:;" title="全部推广计划">全部推广计划</a>
					<ul class="dropdown-menu" role="menu" data-toggle="dropdown">
						<!-- <li>
                            <a data-campaign_id="-1" href="javascript:;" class="campaign_keywords">全部推广计划</a>
                        </li> -->
						<volist name="campaigns" id="v">
							<li>
								<div style="display:inline-block;width:80%;text-align:left;">
									<a data-campaign_id="{$v.campaign_id}" href="javascript:;" class="campaign_keywords">{$v.title}</a>
								</div>
								<if condition="$v.online_status eq online">
									<div class="green campaign_status" style="display:inline-block;width:20%;float:right;">✔</div>
									<else />
									<div class="orange campaign_status" style="display:inline-block;width:20%;float:right;">✘</div>
								</if>

							</li>
						</volist>
					</ul>
				</div>
				<div class="btn-group" id="multi_actions" style="margin-left:0px;">
					<div class="btn-group-dropdown">
						<a  id="addprice"  class="btn btn3 btn_grey btn_higherprice tooltips" href="javascript:void(0);" title="批量增加价格">加价</a>
						<ul class="dropdown-menu" role="menu" data-toggle="dropdown">
							<li><a id="addbyfix" href="javascript:void(0);">原基础上加价</a></li>
							<li><a id="addpricewithratio"  href="javascript:void(0);">按比例加价</a></li>
							<li><a id="setbyfix"  href="javascript:void(0);">统一设置价格</a></li>
						</ul>
					</div>
					<div class="btn-group-dropdown">
						<a id="reduceprice" class="btn btn3 btn_grey btn_lowerprice tooltips" href="javascript:void(0);" title="批量减价价格">减价</a>
						<ul class="dropdown-menu" role="menu" data-toggle="dropdown">
							<li><a id="reducebyfix" href="javascript:void(0)">原基础上减价</a></li>
							<li><a id="reducebyratio" href="javascript:void(0)">按比例减价</a></li>
							<li><a id="setbyfix2" href="javascript:void(0)">统一设置价格</a></li>
						</ul>
					</div>
					<div class="btn-group-dropdown">
						<a id="matchscope" class="btn btn3 btn_grey btn_matchscope tooltips" href="javascript:void(0);" title="批量修改匹配模式">匹配模式</a>
						<ul class="dropdown-menu" role="menu" data-toggle="dropdown">
							<li><a id="fuzzy" href="javascript:void(0)">广泛匹配</a></li>
							<li><a id="center" href="javascript:void(0)">中心词匹配</a></li>
							<li><a id="fix" href="javascript:void(0)">精准匹配</a></li>
						</ul>
					</div>
					<a id="deletewords" class="btn btn3 btn_grey btn_trash tooltips" href="javascript:void(0);" title="批量删除词">删词</a>
					<a id="realtimerank" class="btn btn3 btn_grey btn_list tooltips" href="javascript:void(0);" title="实时排名查询">实时排名</a>
					<a id="cancelchanges" class="btn btn3 btn_grey btn_list tooltips" href="javascript:void(0);" title="取消所选的修改">取消修改</a>
				</div>
			</if>
			<!-- <div style="display:inline">
				当前选择的推广计划：<span class="campaign_name" style="color:red"></span>
			</div> -->

			<div style="float:right;">
				<div id='table_datepicker'></div>
			</div>
			<!--<div class="paging-box paging-full" id="page_html" style="display:inline-block;margin-right:20px;"></div>-->
		</div>
		<br class="clearall" />
		<!--<div style="margin:5px 0 0 5px;" class="keyword-platform">
			<a class="btn btn3 btn_grey btn_highlight disabledBtn" data-form=0 style="border-left:0px;background-color:#229fdd;" href="javascript:;">汇总</a>&nbsp;
			<a class="btn btn3 btn_grey btn_highlight " data-form=1 style="border-left:0px;background-color:#229fdd;" href="javascript:;">计算机</a>&nbsp;
			<a class="btn btn3 btn_grey btn_highlight" data-form=2 style="border-left:0px;background-color:#229fdd;" href="javascript:;">移动设备</a>
		</div>-->
		<div id="fakeThead"  style="clear:both;margin-bottom:0px;margin-top:10px;">
			<table cellpadding="0" cellspacing="0" border="0" class="metrotable datatable" id="kh_dyntable" >
				<thead id="km_thead" style="width: 100%;">
				<tr>
					<th width="40px" class="head0 nolborder" style="padding: 0;">
						<a id="selectall" style="border:0px;text-indent:-9999px;" class="btn btn3 btn_unselectall btn_selectall tooltips" href="javascript:void(0);" title="全选">全选</a>
					</th>
					<th width="75px" class="head1">关键词 ( <span id="keyword_count">0</span> 个)</th>
					<th width="170px" class="head0 center">推广单元名称</th>
					<th width="42px" class="head1 sortable desc" data-sort='impressions'>展现量</th>
					<th width="43px" class="head0 sortable" data-sort='click'>点击量</th>
					<th width="43px" class="head1 sortable" data-sort='ctr'>点击率</th>
					<th width="44px" class="head0 sortable" data-sort='cpc'>平均点击花费</th>
					<th width="44px" class="head1 sortable" data-sort='cvr'>点击转化率</th>
					<th width="44px" class="head0 sortable" data-sort='avgpos'>宝贝排名</th>
					<th width="44px" class="head1 sortable" data-sort='ravgpos'>实时排名</th>
					<th width="44px" class="head0 sortable" data-sort='qscore'>计算机质量得分</th>
					<th width="44px" class="head0 sortable" data-sort='wireless_qscore'>移动质量得分</th>
					<th width="44px" class="head1 sortable" data-sort='cost'>总花费</th>
					<th width="44px" class="head0 sortable" data-sort='sales'>总成交金额</th>
					<th width="44px" class="head0 sortable" data-sort='total_pay_count'>总成交笔数</th>
					<th width="44px" class="head1 sortable" data-sort='roi'>投入产出比</th>
					<th width="44px" class="head0 sortable" data-sort='fav_count'>总收藏数</th>
					<th width="44px" class="head0 sortable" data-sort='fav_count_rate'>收藏率</th>
					<th width="44px" class="head0 sortable" data-sort='cart_total'>购物车数</th>
					<th width="44px" class="head0 sortable" data-sort='cart_total_rate'>购物车率</th>
					<th width="46px" class="head1">出价(计算机)</th>
					<th width="46px" class="head0">出价(移动)</th>
					<th width="77px" class="head1">操作</th>
				</tr>
				</thead>
				<tbody id="keywords_tbody">

				</tbody>
			</table>
		</div>
	</div>
</div>
<div id="keyword_manager">
	<div style="height:200px;text-align:center">
		正在加载关键词信息，请稍后<img src="/Img/loader1.gif" />
	</div>
</div>

<!-- 增量改价  -->

<div class="widget adjustpricewidget" id="adjustbyfix_panel" style="display:none;">
	<div class="row">
		<div class="setPlatform"></div>
		<p>在原价基础上<b class="action_str" class="important">增加</b>关键词出价</p>
		<label>批量 <b class="action_str" class="important">加价</b> </label>
		<div class="input-prepend small-price" >
			<span class="add-on">￥</span>
			<input type="text" class="price smallprice currencyinput" name="incremental" id="incremental" value="0.05" style="width:50px;"/>
		</div>
		<br class="clearall" />
		<label class="max_label">但最高不超过</label>
		<div class="input-prepend small-price" >
			<span class="add-on">￥</span>
			<input type="text" class="price smallprice currencyinput" name="max_price" id="max_price"  value="0.00" style="width:50px;" />
		</div>
	</div>
</div>

<!-- 按比例改价  -->

<div class="widget adjustpricewidget" id="adjustbyratio_panel" style="display:none;">
	<div class="row">
		<div class="setPlatform"></div>
		<p>在原价基础上<b class="action_str" class="important">按比例增加</b>关键词出价</p>
		<div style="vertical-align:middle;">
			<label>按比例 <b class="action_str" class="important">加价</b> </label>
				    <span class="field">
					    <select name="incrsratio" id="increaseratio">
							<option value="5">5%</option>
							<option value="10">10%</option>
							<option value="15">15%</option>
							<option value="20">20%</option>
							<option value="25">25%</option>
							<option value="30">30%</option>
							<option value="40">40%</option>
							<option value="50">50%</option>
							<option value="60">60%</option>
							<option value="70">70%</option>
							<option value="80">80%</option>
							<option value="90">90%</option>
							<option value="100">100%</option>
						</select>
				    </span>
			<label class="max_label">但最高不超过 </label>
			<div class="input-prepend small-price" >
				<span class="add-on">￥</span>
				<input type="text" class="price smallprice currencyinput" name="max_price" id="max_price"  value="0.00" style="width:50px;" />
			</div>
		</div>
	</div>
</div>


<!-- 统一改价  -->

<div class="widget adjustpricewidget" id='setprice_panel' style="display:none;">
	<div class="row">
		<div class="setPlatform"></div>
		<p>把当前选择的所有关键词的价格统一设置为一个价格</p>
		<label>设置价格为</label>
		<span class="field">
		    <select id="user_default" name="adjustaction">
				<option value="0">统一设置价格为</option>
				<option value="1">推广组默认出价</option>
			</select>
	    </span>
		<div class="input-prepend small-price">
			<span class="add-on">￥</span>
			<input type="text" class="price smallprice currencyinput" name="fixedprice" id="fixedprice" value="0.05" style="width:50px;"/>
		</div>
	</div>
</div>

<script>
	var time_from = '{$time_search.from}',
			time_to = '{$time_search.to}';
	var ADGROUP_ID = '{$adgroup_id}';
	var CATEGORY_ID = 1;
	var PRODUCT_ID = 1;
	var CAMPAIGN_ID = '{$campaign_id}';
	var TYPE = 1;
	var TOOLBAR = null;
	//计算屏幕高度来设定每页显示关键词数量
	var w_height =  Math.floor( $(document).height() * 0.7 );
	var w_width = Math.floor( $(document).width() * 0.85 );
	var global_pageSize = Math.floor( ( w_height - 100 ) / 35.0 );
	var manager_pageSize =  Math.floor( ( $(document).height()  - 300 ) / 38.0 );
	var copy_pageSize = Math.floor( ( $(document).height()  - 300 ) / 100.0 );
	var box_container = $('<div id="keyword_helper" ></div>');
	box_container.css({
		width : w_width,
		height : w_height
	});

	// 执行我的思路
	var myThinkingConfig = {
				status : {$is_run_myThink.status},
			value : {$is_run_myThink.value}
	};
	<if condition="$is_run_kawei">
		var kawei = new $.kaweiHelper();
	var pyth = '{$path}';
	var run_kawei = $.cookie("kaweiSetting");
	var type = $.getUrlParam('type');
	<else/>
	var run_kawei = false,
			type = false;
	</if>
	//manager
	var myKeywordManager = new $.ikeywordManager("#fakeThead" , '' , {
				category_id : '1',

				product_id : '1',
				default_price :  '1',
				//pageSize: manager_pageSize
				pageSize : 400
			}
	);
	myKeywordManager.setParams({from:time_from,to:time_to,campaign_id: CAMPAIGN_ID,adgroup_id : ADGROUP_ID, is_run_myThinking: myThinkingConfig});
	myKeywordManager.init();

	//helper
	/*	var selector = new $.ikeywordHelper("#keyword_helper" , {} , {
	 open : true,
	 params : {
	 campaign_id : '1' ,
	 product_id : '1',
	 adgroup_id : '1',
	 category_id : '1',
	 from : Date.today().add({ days: -7 }).toString('yyyy-MM-dd'),
	 to : Date.today().toString('yyyy-MM-dd'),
	 pageSize : '1'
	 }
	 });*/
	var selector = $.keywordSelector(box_container,{
		open : true,
		params : {
			campaign_id : '1' ,
			product_id : '1',
			adgroup_id : '1',
			category_id : '1',
			from : Date.today().add({ days: -7 }).toString('yyyy-MM-dd'),
			to : Date.today().toString('yyyy-MM-dd'),
			pageSize : '1'
		}
	} );

	//APP BAR
	_appbar = new appBar();
	_appbar.addBtn({
		id : 'saveChangesBtn',
		icon : 'check.png',
		name : '提交到直通车',
		onclick : myKeywordManager.saveChanges
	});

	// datepicker
	var _datepicker = new wt.datepicker("#table_datepicker" , {
		placeholder : time_from + ' 到 ' + time_to,
		onChange : function(start,end){
			myKeywordManager.setParams({
				currentPage : 1,
				from : start,
				to : end,
				filter : {
					impressions : {min :0 , max: 0},
					click : {min :0 , max:0},
					ctr : {min :0 , max:0},
					price : {min :0 , max:0},
					max_mobile_price : {min :0 , max:0},
					cpc : {min :0 , max:0},
					sales : {min : 0 , max : 0},
					cost : {min : 0 , max : 0},
					// matchscope : {min : 1 , max : 4},
					qscore : {min : 0 , max : 0},
					wireless_qscore : {min : 0 , max : 0},
					avgpos : {min : 0 , max : 0},
					cpm : {min : 0 , max : 0},
					cvr : {min : 0 , max : 0},
					roi : {min : 0 , max : 0},
					cart_total : {min : 0 , max : 0},
					fav_count: {min: 0, max : 0}
				}
			});
			myKeywordManager.init();
			$(document).find('.rangerSpan').each(function() {
				$(this).text('全部显示');
			});
			// myKeywordManager.getBoundary();
		}
	});



	function initKeywordManagerToolbar()
	{
		$("#keywords_toolbar").find("#page_html li").click(function() {
			var new_page = $(this).find("a").data('page');
			myKeywordManager.setParams({currentPage: new_page});
			myKeywordManager.init();
		});

		$("#keywords_toolbar").find("#page_html .to_page").click(function() {
			var new_page = $(this).parent('.form').find('input').val();
			myKeywordManager.setParams({currentPage: new_page});
			myKeywordManager.is_sort(true);
			myKeywordManager.init();
		})

		var _toolbar = $("#keywords_toolbar");
		_toolbar.find('#multi_actions .btn-overlay').remove();
		_toolbar.find('#multi_actions').append('<div class="btn-overlay">&nbsp;</div>');



		_toolbar.find('.campaign_keywords').click(function() {
			$(".campaign_name").html($(this).text());
			myKeywordManager.setParams({ campaign_id : $(this).data('campaign_id'),currentPage:1,adgroup_id:-1 });
			myKeywordManager.init();
		});

		// _toolbar.find('.campaign_keywords').click(function() {
		// 	$(".campaign_name").html($(this).text());
		// 	myKeywordManager.setParams({ campaign_id : $(this).data('campaign_id') });
		// 	myKeywordManager.init();
		// });

		_toolbar.find('#selectall').on('click' , function(){
			$(this).toggleClass('btn_unselectall');
			myKeywordManager.selectAll();
		});

		//增加价格toolbar
		_toolbar.find('#addprice').dropdown();
		_toolbar.find('#addbyfix').bind('click' , function(){
			var $btn = $(this);
			var panel = $('#adjustbyfix_panel');
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.find('.action_str').text('加价');
			panel.find('.max_label').text('最高不得多于');
			panel.show();
			wt.showBox( panel , '批量加价' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'addbyfix';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.increasemental = getCents( panel.find("#incremental").val() );
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});
		});

		_toolbar.find('#addpricewithratio').bind('click' , function(){

			var $btn = $(this);
			var panel = $('#adjustbyratio_panel');
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.find('.action_str').text('加价');
			panel.find('.max_label').text('最高不得多于');
			panel.show();
			wt.showBox( panel , '批量按比例加价' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'addbyratio';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.increaseratio = panel.find("#increaseratio").val();
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});

		});


		_toolbar.find('#setbyfix').bind('click' , function(){
			var $btn = $(this);
			var panel = $('#setprice_panel');
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.show();
			wt.showBox( panel , '统一设置价格为' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'setbyfix';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.fixedprice = getCents( panel.find("#fixedprice").val() );
					adjust_data.use_default = panel.find("#user_default").val();
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});
		});


		//减少价格toolbar
		_toolbar.find('#reduceprice').dropdown();
		_toolbar.find('#reducebyfix').bind('click' , function(){
			var $btn = $(this);
			var panel = $('#adjustbyfix_panel');
			panel.find(".currencyinput").priceFormat();
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.find('.action_str').text('减价');
			panel.find('.max_label').text('最低不得少于');
			panel.show();
			wt.showBox( panel , '批量减价' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'reducebyfix';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.increasemental = getCents( panel.find("#incremental").val() );
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});
		});

		_toolbar.find('#reducebyratio').bind('click' , function(){
			var $btn = $(this);
			var panel = $('#adjustbyratio_panel');
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.find(".currencyinput").priceFormat();
			panel.find('.action_str').text('减价');
			panel.find('.max_label').text('最低不得少于');
			panel.show();
			wt.showBox( panel , '批量按比例减价' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'reducebyratio';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.increaseratio = panel.find("#increaseratio").val();
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});
		});

		_toolbar.find('#setbyfix2').bind('click' , function(){
			var $btn = $(this);
			var panel = $('#setprice_panel');
			panel.find('.setPlatform').html('');
			panel.find('.setPlatform').html('<span>计算机：<input type="radio" name="platform" value="1" checked="checked"></span>&nbsp;&nbsp;<span>移动：<input type="radio" name="platform" value="0"></span>');
			panel.find(".currencyinput").priceFormat();
			panel.show();
			wt.showBox( panel , '统一设置价格为' , function(r){
				panel.hide().appendTo('body');
				if(r){
					var adjust_data = {};
					adjust_data.adjusttype = 'setbyfix';
					adjust_data.platform = parseInt(panel.find('[name=platform]:checked').val());
					adjust_data.fixedprice = getCents( panel.find("#fixedprice").val() );
					adjust_data.use_default = panel.find("#user_default").val();
					adjust_data.max_price = getCents( panel.find("#max_price").val() );
					myKeywordManager.multiAdjustPrice( adjust_data );
				}
			});
		});

		//匹配模式 toolbar
		_toolbar.find('#matchscope').dropdown();
		_toolbar.find('#fuzzy').bind('click' , function(){
			myKeywordManager.multiSetMatchscope(4);
		});

		_toolbar.find('#center').bind('click' , function(){
			myKeywordManager.multiSetMatchscope(2);
		});

		_toolbar.find('#fix').bind('click' , function(){
			myKeywordManager.multiSetMatchscope(1);
		});


		_toolbar.find('#deletewords').bind('click' , myKeywordManager.multiDelete);
		_toolbar.find('#realtimerank').bind('click' , myKeywordManager.multiRank);
		_toolbar.find('#cancelchanges').bind('click' , myKeywordManager.cancelAllChanges);

		_toolbar.find('#related_keywords').on('click' , function(){
			wt.showBox( box_container, '相关词' , function(){
				selector.hide();
			} , false);
			selector.switchMode("#related");
			selector.show();
		});

		_toolbar.find('.tooltips').tipsy({
			gravity : 's',
			delayIn: 500
		});

		_toolbar.find('.tooltips_w').tipsy({
			gravity : 'w',
			delayIn: 500
		});

		return _toolbar;
	}

	// 初始化keyworder manager toolbar
	myKeywordManager.addEvent('afterInit' , function(){
		TOOLBAR = initKeywordManagerToolbar();
	});

	// 显示提交到直通车
	myKeywordManager.addEvent('onChanged', function(num){
		if(num > 0){
			_appbar.show();
		}
	});

	myKeywordManager.addEvent('onRowselect', function(){
		var num = size( myKeywordManager.getSelectedRows() );
		if( num > 0){
			TOOLBAR.find('#multi_actions .btn-overlay').remove();
		}else{
			if($('.btn-overlay').length == 0)
				TOOLBAR.find('#multi_actions').append('<div class="btn-overlay"></div>');
		}

		//check the select status
		if( myKeywordManager.getSelectAllStatus() ){
			$("#selectall").addClass('btn_unselectall');
		}else{
			$("#selectall").removeClass('btn_unselectall');
		}

	});


	var desc = myKeywordManager.getParams('desc');
	var sort =  myKeywordManager.getParams('sort');
	var sortIndex = $(this).attr('data-sort');
	var sortOrder = desc ? false : true ;
	$(this).parent().find("th").removeClass('sorting_desc sorting_asc');
	$(this).addClass(
			desc ? 'sorting_desc' : 'sorting_asc'
	);
	myKeywordManager.setParams({sort: sortIndex, desc: sortOrder,currentPage:1});
	myKeywordManager.is_sort(true);
	myKeywordManager.init();
</script>

<!-- 查看关键词历史 -->
<script id="keywordlog_panel" type="text/html" >
	<div class="widget" style="width:880px;">

		<div class="two_third" id="khistorygraph">
			<table cellspacing="0" cellpadding="0" border="0" class="metrotable overviewtable" style="margin-bottom:20px;">
				<colgroup>
					<col width="16%" class="con0">
					<col width="16%" class="con1">
					<col width="17%" class="con0">
					<col width="17%" class="con1">
					<col width="17%" class="con0">
					<col width="17%" class="con1">
				</colgroup>
				<thead>
				<tr>
					<th class="head1">浏览量</th>
					<th class="head0">点击量</th>
					<th class="head1">点击率</th>
					<th class="head0">每点击花费</th>
					<th class="head0">总花费</th>
					<th class="head1">总成交</th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td class="indicators"><%= summary.impressions%></td>
					<td class="indicators"><%= summary.click%></td>
					<td class="indicators"><%= summary.ctr%>%</td>
					<td class="indicators">￥<%= summary.cpc%></td>
					<td class="indicators orange">￥<%= summary.cost%></td>
					<td class="indicators orange">￥<%= summary.sales%></td>
				</tr>
				</tbody>
			</table>

			<div id="keyword_chart" style="height:260px;">
			</div>
		</div>

		<div class="one_third last">
			<h4 style="margin:0px;font-size:14px;" class="campaign_select_title">"<%= keyword%>"操作历史</h4>
			<ul class="normal_list" style="margin-bottom:10px;">
				<% for (var i = 0; i < logs.length; i ++) { %>
				<li style="padding-left:0">
					<span>[ <%= logs[i].updated_time%> ]</span>
					<%= logs[i].action_note %>
					<% if (logs[i].action_type == 'auto') { %>
					<span class="label label-warning">自动</span>
					<% }else{ %>
					<span class="label">手动</span>
					<% } %>
				</li>
				<%}%>
			</ul>
		</div>
	</div>
</script>

<!-- 卡位模块 -->
<style>
	.h80{height: 80px !important;}
	.norborder{border: none !important;}
	#keywordTop .input-append, .input-prepend {
		display: block;
	}
	.topSetting {
		/*background: red;*/
	}
	.topSetting input[type="text"] {
		border: none;
		border-bottom: 1px solid #D8D8D8;
		margin-left: 5px;
		padding-left: 5px;
		width: 40px;
	}
	.topSetting .setting-base {
		height: 40px;
		/*max-height: 150px;*/
		line-height: 40px;
		margin: 10px 0px;
		border: 1px solid #D8D8D8;
		padding-left: 20px;
	}
	.topSetting .setting-base .option-name{
		display: inline-block;
		float: left;
		width: 100px;
		height: 100%;
		text-align: right;
		padding-right: 10px;
		/*background:red;*/
	}
	.topSetting .setting-base .option-content {
		/*background: green;*/
	}
</style>
<script>
	$(".keyword-platform").on('click', 'a', function() {
		var $this = $(this);
		myKeywordManager.setParams({
			filter : {
				impressions : {min :0 , max: 0},
				click : {min :0 , max:0},
				ctr : {min :0 , max:100},
				price : {min :0 , max:100},
				max_mobile_price : {min :0 , max:100},
				cpc : {min :0 , max:100},
				sales : {min : 0 , max : 0},
				cost : {min : 0 , max : 0},
				avgpos : {min : 0 , max : 100},
				cpm : {min : 0 , max : 100},
				cvr : {min : 0 , max : 0},
				roi : {min : 0 , max : 0},
				cart_total : {min : 0 , max : 0}
			},
			platform : parseInt($this.data('form'))
		});
		myKeywordManager.init();
		$(document).find('.rangerSpan').each(function() {
			$(this).text('全部显示');
		});
		myKeywordManager.getBoundary();
		$(".keyword-platform a").removeClass('disabledBtn');
		$this.addClass('disabledBtn');
	})
</script>
<script>

	/*
	 $('#km_thead').affix({
	 offset : 190
	 });
	 $("#km_thead").width(  $('#keyword_manager').width() );
	 $("#km_thead").css("margin-top:100px;");

	 */

	$(function(){

		var resetTop=$("table thead").offset().top;

		$(window).scroll(function() {

			// 锁定
			if($(window).scrollTop()>=$("table thead").offset().top){
				$("table thead").css({
					"position": 'fixed',
					"top":"0"
				});
			}
			//解锁
			if($(window).scrollTop()<=resetTop){
				$("table thead").css({
					"position": 'relative'
				});
			}

		});

	})

	$('#km_thead .sortable').on('click' , function(){
		var desc = myKeywordManager.getParams('desc');
		var sortIndex = $(this).attr('data-sort');
		$(this).parent().find("th").removeClass('sorting_desc sorting_asc');
		$(this).addClass(
				desc ? 'sorting_desc' : 'sorting_asc'
		);
		myKeywordManager.setParams({sort:$(this).attr('data-sort'), desc: desc ? false : true});
		myKeywordManager.init();
	});
</script>
<!-- 查看关键词历史 -->
<script id="keywordlog_panel" type="text/html" >
	<div class="widget" style="width:880px;">

		<div class="two_third" id="khistorygraph">
			<table cellspacing="0" cellpadding="0" border="0" class="metrotable overviewtable" style="margin-bottom:20px;">
				<colgroup>
					<col width="16%" class="con0">
					<col width="16%" class="con1">
					<col width="17%" class="con0">
					<col width="17%" class="con1">
					<col width="17%" class="con0">
					<col width="17%" class="con1">
				</colgroup>
				<thead>
				<tr>
					<th class="head1">浏览量</th>
					<th class="head0">点击量</th>
					<th class="head1">点击率</th>
					<th class="head0">每点击花费</th>
					<th class="head0">总花费</th>
					<th class="head1">总成交</th>
				</tr>
				</thead>
				<tbody>
				<tr>
					<td class="indicators"><%= summary.impressions%></td>
					<td class="indicators"><%= summary.click%></td>
					<td class="indicators"><%= summary.ctr%>%</td>
					<td class="indicators">￥<%= summary.cpc%></td>
					<td class="indicators orange">￥<%= summary.cost%></td>
					<td class="indicators orange">￥<%= summary.sales%></td>
				</tr>
				</tbody>
			</table>

			<div id="keyword_chart" style="height:260px;">
			</div>
		</div>

		<div class="one_third last">
			<h4 style="margin:0px;font-size:14px;" class="campaign_select_title">"<%= keyword%>"操作历史</h4>
			<ul class="normal_list" style="margin-bottom:10px;">
				<% for (var i = 0; i < logs.length; i ++) { %>
				<li style="padding-left:0">
					<span>[ <%= logs[i].updated_time%> ]</span>
					<%= logs[i].action_note %>
					<% if (logs[i].action_type == 'auto') { %>
					<span class="label label-warning">自动</span>
					<% }else{ %>
					<span class="label">手动</span>
					<% } %>
				</li>
				<%}%>
			</ul>
		</div>
	</div>
</script>


<script type="text/javascript">
	var campaign_id = {$campaign_id};
	$(document).ready(function(){
		var $container = $('#keyword_manager');
		var keywordManager = $.keywordManager($container, {
			params: {
				campaign_id: campaign_id
			}
		});
		keywordManager.init(function(){
			$container.find('.loading').hide();
		});
	});
</script>